﻿using SocketWeaver.FixedMath;
using System;

namespace SocketWeaver.FPhysics2D
{
    [Serializable]
    internal class FPhysicsBody2D : NativeObject
    {
        public FVector2 position;
        public FFloat angle;

        internal FVector2 linearVelocity;
        internal FFloat angularVelocity;

        public FFloat mass;

        public UInt16 bodyID { get; private set; }
        public UInt32 externalID { get; private set; }

        internal FRigidbody2D rigidBody { get; private set; }

        public FPhysicsBody2D(IntPtr intPtr, UInt16 bodyID, UInt32 externalID, FRigidbody2D rigidBody) : base(intPtr)
        {
            this.bodyID = bodyID;
            this.externalID = externalID;
            this.rigidBody = rigidBody;
        }

        public void SyncTransform()
        {
            rigidBody.fTransform.position = (FVector3)position;

            rigidBody.fTransform.rotation = FQuaternion.FromEulerRad1(new FVector3(FFloat.zero, FFloat.zero, angle));
            //FPhysics2D.ReadNativeBody(this);
            //this.rigidBody.OnTransformUpdated();
        }

        public void SyncEnabled()
        {
            rigidBody.gameObject.SetActive(NativeFPPhysics2D.IsEnabled(IntPointer));
        }
    }
}
